package com.ww.springboot.boot.test;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.google.common.collect.Lists;
import com.ww.springboot.boot.test.ForecastLogDTO;
import com.ww.springboot.boot.utils.Func;
import com.ww.springboot.boot.utils.ObjectUtil;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 描述：
 *
 * @author wanwei
 * @since 2021-06-30 10:11
 */
public class RetryTest3 {

    public static void main(String[] args) throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("/static/text/code.txt");
        String ids = IOUtils.toString(classPathResource.getInputStream(), "utf-8");




        List<String> typeList = new ArrayList<>();
        //typeList.add("forecast_charge_queue");
        //typeList.add("handing_order_queue");
        //typeList.add("label_check_queue");
        typeList.add("callBack_trackNo_queue");
        //typeList.add("generate_trackNos_queue");
//        typeList.add("callBack_label_queue");
        //typeList.add("generate_cancelOrder_queue");
        //typeList.add("delivery_charge_queue");
        //typeList.add("generate_label_queue");

        List<String> listAll;
        if(ids.indexOf(",") > 0){
            listAll = Func.toStrList(",",ids);
        }else {
            listAll = Func.toStrList("\r\n",ids);
        }

        List<List<String>> partition = Lists.partition(listAll, 5000);
        for(String type :typeList){
            partition.forEach(list->{
                List<ForecastLogDTO> dtos = new ArrayList<>();
                for (String id : list) {
                    ForecastLogDTO forecastLogDTO = new ForecastLogDTO();
                    forecastLogDTO.setBizType(1);
                    forecastLogDTO.setConsumerQueue(type);
                    forecastLogDTO.setMqMessage("{\"id\":" + id + "}");
                    dtos.add(forecastLogDTO);
                }
                String msg = JSONUtil.toJsonStr(dtos);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(msg);
                String body = HttpRequest.post("http://cotms-forecast.box-tools.com/forecast/log/retryList").body(msg).execute().body();
                System.out.println(body);
            });

        }
    }
}
